#!/usr/bin/perl

use strict;

sub usage()
{
	print <<END;
usage: $0 epub_Filename
END
	exit(1);
}

if (scalar(@ARGV) != 1) {
	usage;
}

my $epub_file = shift(@ARGV);

if (! -e "mimetype") {
	die "error: cannot locate file 'mimetype'\n";
}

if (-e $epub_file) {
	if (unlink($epub_file) != 1) {
		die "error: unable to remove $epub_file\n";
	}
}

my $zip_results = `zip -X -q -0 "$epub_file" mimetype`;
$zip_results = `zip -q -r "$epub_file" * -x mimetype`;


if (-e $epub_file) {
	print "created $epub_file\n";
} else {
	die "error: failed to create $epub_file\n";
}

exit(0);
